package com.apimarket.controller;

import com.apimarket.entity.Result;
import com.apimarket.entity.Type;
import com.apimarket.service.TypeService;
import com.apimarket.util.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description:
 * @Author ZXR
 * @Date 2021/6/24 21:22
 * @Version 1.0
 */

@RestController
@RequestMapping("/type")
public class TypeController {
    @Autowired
    private TypeService typeService;
    //set在redis中的key
    @Value("${redis.set.type}")
    private String redisSetType;
    @Autowired
    private RedisUtils redisUtils;

    @RequestMapping("/getTypeList")
    public Result<List<Type>> getTypeList(){
        List<Type> data=null;
        data= (List<Type>) redisUtils.judgeAndGet(redisSetType);
        if(data==null){
            //从数据库中拿
            data=typeService.getTypeList();
            redisUtils.set(redisSetType,data);
        }
        return new Result<>(data,200,"success");
    }

}
